package com.daykw.xiaohongshu.task;

import java.util.Iterator;

import org.apache.log4j.Logger;
import org.ehcache.Cache;
import org.nutz.dao.Cnd;
import org.nutz.dao.impl.NutDao;

import com.daykw.xiaohongshu.model.Ips;
import com.daykw.xiaohongshu.util.EhcacheUtils;
import com.daykw.xiaohongshu.util.SpringContextHolder;

public class ClearIpPoolTask implements Runnable {
	private static Logger logger = Logger.getLogger(ClearIpPoolTask.class);

	@Override
	public void run() {
		NutDao dao = SpringContextHolder.getBean("dao");

		Iterator<Cache.Entry<String, String>> its = EhcacheUtils.getInstance().getCacheKeys();
		int count = 0;

		while (its.hasNext()) {
			Cache.Entry<String, String> kv = its.next();
			String key = kv.getKey();
			dao.clear(Ips.class, Cnd.where("ips", "=", key));
			count++;
		}
		logger.info("#######清除了" + count + "个无用IP#######");
	}

}
